<template>
  <div class="section" :class="{ 'section--full': full, 'section--scrollbar': scrollbar }">
    <div class="section-header">
      <div class="section-title" v-if="title">{{ title }}</div>

      <div class="section-icon">
        <slot name="icon"> </slot>
      </div>

      <div v-if="allowFold" class="arrow" @click="fold = !fold" :class="{ 'arrow--fold': fold }">
        <el-icon><ArrowUpBold /></el-icon>
      </div>
    </div>
    <transition name="slide">
      <div class="section-body" v-show="!fold">
        <template v-if="scrollbar">
          <el-scrollbar> <slot></slot></el-scrollbar>
        </template>
        <slot v-else> </slot>
      </div>
    </transition>
  </div>
</template>
<script setup>
const fold = defineModel('fold', {
  type: Boolean, // 指定类型
  default: false, // 默认值
})

const props = defineProps({
  title: String,
  full: Boolean,
  scrollbar: Boolean,
  allowFold: Boolean,
})
</script>
<style lang="scss" scoped>
.section {
  margin-bottom: 16px;
  overflow: hidden;

  // border: 1px solid #e5e6eb;

  background-color: #fff;
  box-shadow: 0 1px 8px rgba(0, 0, 0, 0.03);
  border: 1px solid #f0f0f0;
  border-radius: 8px;

  padding: 12px;

  &:last-child {
    margin-bottom: 0;
  }
}

.section-header {
  display: flex;
  align-items: center;
  position: relative;
}

.section-title {
  font-size: 16px;
  color: #000;
  font-weight: bold;
}

.arrow {
  cursor: pointer;
  transition: all 0.3s ease;
  color: #999;
  position: absolute;
  right: 0;
  top: 50%;
  margin-top: -4px;
}

.arrow--fold {
  transform: rotate(-180deg);
}

.section-body {
  margin-top: 12px;
}

.section--full {
  display: flex;
  flex-direction: column;
  .section-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
}

.section-icon {
  margin-left: 8px;
  font-size: 20px;
}

/* 折叠动画效果 */
.slide-enter-active,
.slide-leave-active {
  transition: all 0.3s ease;
  max-height: 1000px; /* 设置一个足够大的值 */
  overflow: hidden;
}

.slide-enter-from,
.slide-leave-to {
  max-height: 0;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
}
</style>
